home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Library / Manuels & Misc / Assembly / AOA.ZIP / CH05 / PGM5_1.ASM < prev    next >
Encoding:
Assembly Source File  |  1994-10-14  |  2.8 KB  |  111 lines

  1. ; Sample variable declarations
  2. ; This sample file demonstrates how to declare and access some simple
  3. ; variables in an assembly language program.
  4. ;
  5. ; Randall Hyde
  6. ;
  7. ;
  8. ; Note: global variable declarations should go in the "dseg" segment:
  9.  
  10. dseg        segment    para public 'data'
  11.  
  12. ; Some simple variable declarations:
  13.  
  14. character    byte    ?        ;"?" means uninitialized.
  15. UnsignedIntVar    word    ?
  16. DblUnsignedVar    dword    ?
  17.  
  18. ;You can use the typedef statement to declare more meaningful type names:
  19.  
  20. integer        typedef    sword
  21. char        typedef    byte
  22. FarPtr        typedef    dword
  23.  
  24. ; Sample variable declarations using the above types:
  25.  
  26. J        integer    ?
  27. c1        char    ?
  28. PtrVar        FarPtr    ?
  29.  
  30.  
  31. ; You can tell MASM & DOS to initialize a variable when DOS loads the
  32. ; program into memory by specifying the initial value in the operand
  33. ; field of the variable's declaration:
  34.  
  35. K        integer    4
  36. c2        char    'A'
  37. PtrVar2        FarPtr    L        ;Initializes PtrVar2 with the
  38.                     ; address of L.
  39.  
  40.  
  41. ; You can also set aside more than one byte, word, or double word of
  42. ; storage using these directives.  If you place several values in the
  43. ; operand field, separated by commas, the assembler will emit one byte,
  44. ; word, or dword for each operand:
  45.  
  46. L        integer    0, 1, 2, 3
  47. c3        char    'A', 0dh, 0ah, 0
  48. PtrTbl        FarPtr    J, K, L
  49.  
  50. ; The BYTE directive lets you specify a string of characters byte enclosing
  51. ; the string in quotes or apostrophes.  The directive emits one byte of data
  52. ; for every character in the string (not including the quotes or apostrophes
  53. ; that delimit the string):
  54.  
  55. string        byte    "Hello world",0dh,0ah,0
  56.  
  57.  
  58. dseg        ends
  59.  
  60.  
  61.  
  62.  
  63.  
  64. ; The following program demonstrates how to access each of the above
  65. ; variables.
  66.  
  67. cseg        segment    para public 'code'
  68.         assume    cs:cseg, ds:dseg
  69.  
  70. Main        proc
  71.         mov    ax, dseg    ;These statements are provided by
  72.         mov    ds, ax        ; shell.asm to initialize the
  73.         mov    es, ax        ; segment register.
  74.  
  75.  
  76. ; Some simple instructions that demonstrate how to access memory:
  77.  
  78.         lea    bx, L        ;Point bx at first word in L.
  79.         mov    ax, [bx]    ;Fetch word at L.
  80.         add    ax, 2[bx]    ;Add in word at L+2 (the "1").
  81.         add    ax, 4[bx]    ;Add in word at L+4 (the "2").
  82.         add    ax, 6[bx]    ;Add in word at L+6 (the "3").
  83.         mul    K        ;Compute (0+1+2+3)*123.
  84.         mov    J, ax        ;Save away result in J.
  85.  
  86.         les    bx, PtrVar2    ;Loads es:di with address of L.
  87.         mov    di, K        ;Loads 4 into di
  88.         mov    ax, es:[bx][di]    ;Fetch value of L+4.
  89.  
  90.  
  91. ; Examples of some byte accesses:
  92.  
  93.         mov    c1, ' '        ;Put a space into the c1 var.
  94.         mov    al, c2        ;c3 := c2
  95.         mov    c3, al
  96.  
  97. Quit:        mov    ah, 4ch        ;Magic number for DOS
  98.         int    21h        ; to tell this program to quit.
  99. Main        endp
  100.  
  101. cseg        ends
  102.  
  103. sseg        segment    para stack 'stack'
  104. stk        byte    1024 dup ("stack   ")
  105. sseg        ends
  106.  
  107. zzzzzzseg    segment    para public 'zzzzzz'
  108. LastBytes    byte    16 dup (?)
  109. zzzzzzseg    ends
  110.         end    Main
  111.